import 'package:boss/models/package_group.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/packageGroup/page/packageGroupDetail/provider/package_group_detail_provider.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class CommodityRow extends StatelessWidget {
  final CommodityFormList data;

  const CommodityRow({Key key, @required this.data}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: <Widget>[
          Expanded(
            flex: 2,
            child: Text(
              data.commodityNameWithSku,
              style: TextStyleConstant().normal_1_28,
            ),
          ),
          Expanded(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    children: <Widget>[
                      Text(
                        '¥',
                        style: TextStyleConstant().normal_1_28,
                      ),
                      Expanded(
                          child: TextFormField(
                        keyboardType: TextInputType.numberWithOptions(decimal: true),
                        initialValue: data.price == null ? '0' : AmountUtil.price2String(data.price),
                        onChanged: (value) {
                          data.price = AmountUtil.string2Price(value);
                        },
                      )),
                    ],
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    var provider = Provider.of<PackageGroupDetailProvider>(
                      context,
                      listen: false,
                    );
                    provider.removePackageGroupCommodity(data);
                  },
                  child: BaseImage(
                    'assets/image/delete_icon.png',
                    width: 30.w,
                    height: 30.w,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
